<?php

namespace app\common\model;

use think\facade\Cache;
use think\Model;

/**
 * 用户
 */
class User extends BaseModel
{

    // 表名,不含前缀
    protected $name = 'user';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;
    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;

    public function findByToken($token)
    {
        return $this->where("token", $token)->find();
    }

    public function findByOpenId($openId)
    {
        return $this->where("open_id", $openId)->find();
    }

    public function findByPhone($phone)
    {
        return $this->where("phone", $phone)->find();
    }

    /**
     * 得到所有的销售员
     * @return array|\PDOStatement|string|\think\Collection
     */
    public function findBySeller()
    {
        return $this->where("type", 2)->select();
    }

    public function getTypes()
    {
        return [
            [
                "id" => 1,
                "title" => "普通用户"
            ],
            [
                "id" => 2,
                "title" => "销售员"
            ],
        ];
    }

}
